package com.algo.pattern.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件夹节点
 */
public class DirNode extends AbstractNode {
    /**
     * 目录名
     */
    private String name;
    /**
     * 子节点
     */
    private List<AbstractNode> childs;

    public DirNode(String name) {
        this.name = name;
        childs = new ArrayList<>();
    }

    /**
     * 添加子节点
     * @param childNode
     * @throws Exception
     */
    @Override
    protected void addChild(AbstractNode childNode) throws Exception {
        childs.add(childNode);
    }

    /**
     * 移除子节点
     * @param childNode
     * @throws Exception
     */
    @Override
    protected void removeChild(AbstractNode childNode) throws Exception {
        childs.remove(childNode);
    }

    @Override
    public void println() {
        System.out.println("文件夹名称为：" + name);
        for (AbstractNode node : childs) {
            node.println();
        }
    }
}
